package com.lleice.web.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lleice.common.annotation.Permission;
import com.lleice.common.annotation.RequestLog;
import com.lleice.service.entity.sys.SysRequestLog;
import com.lleice.service.qo.sys.RequestLogListPageReq;
import com.lleice.service.service.sys.ISysRequestLogService;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 请求日志相关接口
 * </p>
 *
 * @author lizihao
 * @since 2020-11-18
 */
@Api(tags = {"请求日志接口"})
@RestController
@RequestMapping("/base/requestLog")
public class SysRequestLogController {
	@Autowired
	private ISysRequestLogService iSysRequestLogService;

	@ApiOperation(value = "日志列表")
	@Permission
	@RequestLog
    @RequestMapping(value = "/page", method = RequestMethod.POST)
	public IPage<SysRequestLog> page(@RequestBody RequestLogListPageReq pageReq) throws Exception{
		QueryWrapper<SysRequestLog> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(StrUtil.isNotBlank(pageReq.getRequestMethod()), "request_method", pageReq.getRequestMethod());
		queryWrapper.eq(StrUtil.isNotBlank(pageReq.getRequestIp()),"request_ip", pageReq.getRequestIp());
	 return iSysRequestLogService.page(pageReq.getPage(), queryWrapper);
 }
}
